//------[获取两个日期中所有的月份中]
export function getMonthBetween(start, end) {
    var result = [];
    var s = start.split("-");
    var e = end.split("-");
    var min = new Date();
    var max = new Date();
    min.setFullYear(s[0], s[1]);
    max.setFullYear(e[0], e[1]);
    // console.log(e[0] + "---- " + e[1]);
    var curr = min;
    while (curr <= max) {
        var month = curr.getMonth();
        //month=month==0?12:month;
        // console.log(month);
        var str = curr.getFullYear() + "-" + (month);
        var s = curr.getFullYear() + "-0";
        if (str == s) {
            str = curr.getFullYear() + "-12";
        }
        result.push(str);
        curr.setMonth(month + 1);
    }
    return result;
}
//------[获取两个日期中所有的月份中END]

// 日期月份/天的显示，如果是1位数，则在前面加上'0'
export function getFormatDate(arg) {
    if (arg == undefined || arg == '') {
        return '';
    }

    var re = arg + '';
    if (re.length < 2) {
        re = '0' + re;
    }

    return re;
}

//获取两日期之间日期列表函数
export function getdiffdate(stime, etime) {
    // 给一个日期加一天
    var date = new Date(etime);
    // date.setDate(date.getDate() + 1);
    var month = date.getMonth() + 1;
    var day = date.getDate();
    etime = date.getFullYear() + '-' + getFormatDate(month) + '-' + getFormatDate(day);
    
    //初始化日期列表，数组
    var diffdate = new Array();
    var i = 0;
    //开始日期小于等于结束日期,并循环
    while (new Date(stime).getTime() <= new Date(etime).getTime()) {
        diffdate[i] = stime;

        //获取开始日期时间戳
        var stime_ts = new Date(stime).getTime();
        // console.log('当前日期：' + stime + '当前时间戳：' + stime_ts);

        //增加一天时间戳后的日期
        var next_date = stime_ts + (24 * 60 * 60 * 1000);

        //拼接年月日，这里的月份会返回（0-11），所以要+1
        var next_dates_y = new Date(next_date).getFullYear() + '-';
        var next_dates_m = (new Date(next_date).getMonth() + 1 < 10) ? '0' + (new Date(next_date).getMonth() + 1) + '-' : (new Date(next_date).getMonth() + 1) + '-';
        var next_dates_d = (new Date(next_date).getDate() < 10) ? '0' + new Date(next_date).getDate() : new Date(next_date).getDate();

        stime = next_dates_y + next_dates_m + next_dates_d;

        //增加数组key
        i++;
    }
    return diffdate;
    console.log(diffdate);
}